package ai4games_tests.tests;

import game2dai.Domain;
import game2dai.World;
import game2dai.entities.Vehicle;
import game2dai.entityshapes.ps.ArrowPic;
import game2dai.entityshapes.ps.Hints;
import game2dai.maths.Vector2D;
import game2dai.steering.AutoPilot;
import processing.core.PApplet;

// Pursuit

public class GameTest_003 extends PApplet{
	
	long ct, et, lt;
	float deltaTime;
	
	World w;
	Domain wd;
	
	Vehicle pursuer, pursued;
	ArrowPic view;
	AutoPilot sbPursuit, sbSeekMouse;
	
	Vector2D target;
	
	public void setup(){
		size(600,600);
		w = new World(width, height);
		wd = new Domain(0, 0, width, height);
		
		cursor(CROSS);
		target = new Vector2D(width/2, height/2);
		pursuer = new Vehicle(new Vector2D(20,50), // position
				6, // collision radius
				new Vector2D(20,0), // velocity
				60, // maximum speed
				new Vector2D(1,0), // heading
				1, // mass
				2,  // turning rate
				200 // max force
				); 
		view = new ArrowPic(this);		
		view.showHints(Hints.HINT_HEADING | Hints.HINT_VELOCITY);
//		view.fill(color(255,128,128));
		pursuer.renderer(view);
		pursuer.worldDomain(wd);
		
		pursued = new Vehicle(new Vector2D(width -40,height - 50), // position
				6, // collision radius
				new Vector2D(-30,0), // velocity
				60, // maximum speed
				new Vector2D(-1,0), // heading
				1, // mass
				2,  // turning rate
				200 // max force
				); 
		view = new ArrowPic(this);		
		view.showHints(Hints.HINT_HEADING | Hints.HINT_VELOCITY);
//		view.fill(color(128,128,255));
		pursued.renderer(view);
		pursued.worldDomain(wd);
		
		sbPursuit = new AutoPilot();
//		sbPursuit.setAgent(SBF.AGENT_TO_PURSUE, pursued);
//		sbPursuit.enableBehaviours(SBF.PURSUIT);
		sbPursuit.pursuitOn(pursued);
		target.set(width/2, height/2);
		sbSeekMouse = new AutoPilot();
//		sbSeekMouse.setTarget(SBF.SEEK, target);
//		sbSeekMouse.enableBehaviours(SBF.SEEK);
		sbSeekMouse.seekOn(target);
		pursued.AP(sbSeekMouse);

		ct = lt = millis();
		ellipseMode(CENTER);
		
		w.add(pursuer);
		w.add(pursued);
	}
	
	public void draw(){
		ct = millis();
		et = ct - lt;
		lt = ct;
		deltaTime = et / 1000.0f;
		background(192,255,192);
		stroke(0);
		fill(0);
		text("Select steering behaviour    [P]ursue", 10,20);
		target.set(mouseX, mouseY);
		sbSeekMouse.seekOn(target);
		
		w.update(deltaTime);
		w.draw();
	}
	
	public void keyPressed(){
		if(key == 'p')
			pursuer.AP(sbPursuit);
	}
}
